//
//  ViewController.m
//  ReactNativeDemo
//
//  Created by AceWei on 2017/8/3.
//  Copyright © 2017年 AceWei. All rights reserved.
//

#import "ViewController.h"
#import <React/RCTRootView.h>

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
    UILabel *la = [[UILabel alloc] init];
    [self.view addSubview:la];
    
    la.text = @"Hello";
    la.backgroundColor = [UIColor grayColor];
    
    la.frame = CGRectMake(30, 100, 100, 50);
    la.textAlignment = NSTextAlignmentCenter;
    
    [self addGoRN];
}


- (void)addGoRN
{
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [self.view addSubview:btn];
    
    [btn setTitle:@"High Score" forState:UIControlStateNormal];
    
    btn.frame = CGRectMake(30, 170, 100, 50);
    
    
    [btn addTarget:self action:@selector(highScoreButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
    
    
//    [self performSelector:@selector(highScoreButtonPressed:) withObject:btn];
}


- (IBAction)highScoreButtonPressed:(id)sender {
    NSLog(@"High Score Button Pressed");
    NSURL *jsCodeLocation = [NSURL URLWithString:@"http://localhost:8081/index.ios.bundle?platform=ios"];
    
    RCTRootView *rootView =
    [[RCTRootView alloc] initWithBundleURL: jsCodeLocation
                                moduleName: @"MyReactNativeApp"
                         initialProperties:
     @{
       @"scores" : @[
               @{
                   @"name" : @"Alex",
                   @"value": @"42"
                   },
               @{
                   @"name" : @"Joel",
                   @"value": @"10"
                   }
               ]
       }
                             launchOptions: nil];
    UIViewController *vc = [[UIViewController alloc] init];
    vc.view = rootView;
    [self presentViewController:vc animated:YES completion:nil];
}


@end
